##                         ##
#   Fail2Ban.log Monitor    #
#       Author:Plaix        #
##                         ##

import commands
from time import strftime


class monF2B():
    def __init__(self):
        self.name="Fail2ban log monitor"
        self.result=""
        self.type="LOGIN"
    def check(self):
        global result
        global type
        self.cmd="cat /var/log/fail2ban.log | grep \""+strftime('%d')+" \" | grep \"WARNING\" | grep \"Ban\" | cut -d \" \" -f1,2,7"
        current=[]
        temp=commands.getoutput(self.cmd)
        current=temp.split('\n')
        if(current[-1]!=self.result):
            self.result=current[-1]
            return 1
        else:
            return 0